package com.zj.controller;

import com.zj.controller.Utils.Result;
import com.zj.service.impl.UserServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Slf4j //来自Lombok
@RestController
@RequestMapping("users")
public class UserController {
    @Autowired
    UserServiceImpl userService;
    @GetMapping("{id}")
    public Result selectById(@PathVariable int id){
        return new Result(true,userService.getById(id),"成功");
    }
    @GetMapping()
    public Result selectAll(){
        log.warn("你好");
        return new Result(true,userService.list(null),"成功");
    }
//   @GetMapping()
//    public static String getHttpUrl(HttpServletRequest request){
//        String localAddr = request.getLocalAddr();
//        int serverPort = request.getServerPort();
//        return "http://"+localAddr +":"+ serverPort;
//    }
}
